package com.woniuxy.stage3demo.service.otherPzc.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.stage3demo.bean.otherPzc.AdsBean;
import com.woniuxy.stage3demo.mapper.otherPzc.AdsMapper;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import com.woniuxy.stage3demo.service.otherPzc.IAdsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional(readOnly = true)
public class AdsServiceImpl implements IAdsService {

    @Resource
    private AdsMapper adsMapper;

    /**
     * 新增广告
     *
     * @param adsBean 新增的广告对象
     * @return 数据库操作的行数
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int saveAds(AdsBean adsBean) {
        return adsMapper.saveAds(adsBean);
    }

    /**
     * 删除广告
     *
     * @param id 删除的广告对象的id
     * @return 数据库操作的行数
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int deleteAds(int id) {
        return adsMapper.deleteAds(id);
    }

    /**
     * 修改广告
     *
     * @param adsBean 修改的广告对象
     * @return 操作行数
     */
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int updateAds(AdsBean adsBean) {
        return adsMapper.updateAds(adsBean);
    }

    /**
     * 分页查询
     *
     * @param request
     * @param adminBean
     * @return
     */
    @Override
    public PageInfo<AdsBean> findAllByParams(PageRequest request, AdsBean adminBean) {
        return PageHelper.startPage(request.getPageNum(),request.getLimit()).
                doSelectPageInfo(()->adsMapper.findAllByParams(request,adminBean));
    }


}
